package com.jctrip.hotel.source.model;

import lombok.Data;

/**
 * 接口直连返回格式
 */
@Data
public class Result<T> {

    private Boolean success;

    private Integer code;

    private String message;

    private Long timestamp;

    T result;

    public static <T> Result<T> ok(T data) {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(200);
        result.setMessage("");
        result.setTimestamp(System.currentTimeMillis());
        result.setResult(data);
        return result;
    }

    public static <T> Result<T> ok() {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(200);
        result.setMessage("");
        result.setTimestamp(System.currentTimeMillis());
        result.setResult(null);
        return result;
    }

    public static Result<Void> error(String message) {
        Result<Void> result = new Result<>();
        result.setSuccess(false);
        result.setCode(500);
        result.setMessage(message);
        result.setTimestamp(System.currentTimeMillis());
        result.setResult(null);
        return result;
    }
}
